package Chapter05.animal;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class PersonnelLoginSystem {
    private Map<String, String> personnelMap;

    public PersonnelLoginSystem() {
        personnelMap = new HashMap<String, String>();
    }

    public void addPersonnel(String username, String password) {
        personnelMap.put(username, password);
    }

    public boolean login(String username, String password) {
        if (personnelMap.containsKey(username)) {
            String storedPassword = personnelMap.get(username);
            if (storedPassword.equals(password)) {
                System.out.println("Login successful.");
                return true;
            }
        }
        System.out.println("Incorrect username or password.");
        return false;
    }

    public static void main(String[] args) {
        PersonnelLoginSystem loginSystem = new PersonnelLoginSystem();
        loginSystem.addPersonnel("Alice", "password123");
        loginSystem.addPersonnel("Bob", "qwerty456");
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("Enter username: ");
            String username = scanner.nextLine();
            System.out.print("Enter password: ");
            String password = scanner.nextLine();
            if (loginSystem.login(username, password)) {
                break;
            }
        }
    }
}
